<html>
  <head>
    <meta charset="utf8" />
    <title>Consultation des rencontres</title>
	<link rel="stylesheet" href="style.css" />
  </head>
  <body>
<?php include("connexion-db.php");
include("retour-index.php"); ?>
<p>Les matches du <?php echo $_POST['choix-date-rencontre']; ?> pour la catégorie <?php echo $_POST['choix-categorie']; ?> :
<ul>

<?php
$query1 = 'SELECT NOM_EQUIPE, NOM_CLUB, ID_RENCONTRE
FROM RENCONTRE R, EQUIPE E, CATEGORIE CA, CLUB C
WHERE DATE_RENCONTRE = "'.$_POST['choix-date-rencontre'].'"
AND CA.NOM_CATEGORIE = "'.$_POST['choix-categorie'].'"
AND R.ID_EQUIPE1 = E.ID_EQUIPE
AND E.ID_CAT = CA.ID_CAT
AND CA.ID_CLUB = C.ID_CLUB';

$query2 = 'SELECT NOM_EQUIPE, NOM_CLUB
FROM RENCONTRE R, EQUIPE E, CATEGORIE CA, CLUB C
WHERE DATE_RENCONTRE = "'.$_POST['choix-date-rencontre'].'"
AND CA.NOM_CATEGORIE = "'.$_POST['choix-categorie'].'"
AND R.ID_EQUIPE2 = E.ID_EQUIPE
AND E.ID_CAT = CA.ID_CAT
AND CA.ID_CLUB = C.ID_CLUB';

$res1 = $db->query($query1);
$res2 = $db->query($query2);

while(($data1 = $res1->fetch()) AND ($data2 = $res2->fetch())){
?>
<li><a href="feuille-de-match.php?id-rencontre=<?php echo $data1['ID_RENCONTRE'] ?>"><?php echo $data1['NOM_CLUB'] . ' ' . $data1['NOM_EQUIPE'] . ' - ' . $data2['NOM_CLUB'] . ' ' . $data2['NOM_EQUIPE']; ?></a></li>
<?php } ?>
</ul>

<table>
	<tr>
	<th>Prénom</th>
	<th>Nom</th>
	<th>Club</th>
	<th>Equipe</th>
	<th>Points marqués</th>
	</tr>
      <?php
	 $query = ' SELECT PERSONNE.PRENOM, PERSONNE.NOM, CLUB.NOM_CLUB, EQUIPE.NOM_EQUIPE, SUM(PARTICIPE.POINTS_RENCONTRE) AS S
FROM JOUEUR, PERSONNE, CLUB, EQUIPE, PARTICIPE, RENCONTRE, CATEGORIE
WHERE (PERSONNE.NUMERO_LICENCE = JOUEUR.NUMERO_LICENCE)
AND (PERSONNE.ID_CLUB = CLUB.ID_CLUB)
AND (EQUIPE.ID_EQUIPE = JOUEUR.ID_EQUIPE)
AND (JOUEUR.NUMERO_LICENCE = PARTICIPE.NUMERO_LICENCE)
AND (PARTICIPE.ID_RENCONTRE = RENCONTRE.ID_RENCONTRE)
AND (EQUIPE.ID_CAT = CATEGORIE.ID_CAT)
AND (RENCONTRE.DATE_RENCONTRE = "'.$_POST['choix-date-rencontre'].'")
AND (CATEGORIE.NOM_CATEGORIE = "'.$_POST['choix-categorie'].'")
GROUP BY JOUEUR.NUMERO_LICENCE
ORDER BY S DESC';
	 $res = $db->query($query);
      while($data = $res->fetch()){
	 ?>
      <tr>
	<td><?php echo $data['PRENOM']; ?></td>
	<td><?php echo $data['NOM']; ?></td>
	<td><?php echo $data['NOM_CLUB']; ?></td>
	<td><?php echo $data['NOM_EQUIPE']; ?></td>
	<td><?php echo $data['S']; ?></td>
      </tr>
      <?php } ?>
    </table>
<?php $res1->closeCursor();
$res2->closeCursor();
$res->closeCursor(); ?>
  </body>
</html>
